package com.tl.sun.ui.interfaces;

import android.content.Context;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.tl.sun.AppContext;
import com.tl.sun.OkHeader;

import org.json.JSONObject;

import okhttp3.Call;
import okhttp3.Response;

/**
 * Created by apple on 17/4/17.
 */

public class   StatsLinePresent {
    private StatsLineInterface mInterface;
    private Context mContext;

    public StatsLinePresent(Context context,StatsLineInterface anInterface) {
        mInterface = anInterface;
        mContext = context;
    }

    public void getMsg(int srvId, int type, String lastSrvId){
        OkGo.getInstance().addCommonHeaders(OkHeader.getCommonHeadToken(mContext))
                .post(AppContext.getInstance().getBaseUrl()+"account/deal_connect")
                .params("srv_id",srvId)
                .params("type",type)
                .params("last_srv_id",lastSrvId)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(String s, Call call, Response response) {
                        try {
                            JSONObject jo=new JSONObject(s);
                            String ret=jo.getString("ret");
                            String code=jo.getString("code");
                            String msg=jo.getString("msg");
                            if (ret.equals("0")&&code.equals("1")){
                                mInterface.success(msg);
                            } else if(ret.equals("1")&&code.equals("-1")){
                                mInterface.error(msg);
                            }
                        }catch (Exception e){}
                    }
                });
    }
}
